﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using Telerik.WinControls.UI;

namespace Language_Editor
{
    //  Summary:
    //      vælger et nyt sprog, returnerer en cultureinfo, hvis der ikke trykkes ok returneres null
    //      lav en ny instans og kald getnew() på instansen
    public partial class PickLanguage : Telerik.WinControls.UI.RadForm
    {
        private CultureInfo newLanguage;
        public PickLanguage()
        {
            InitializeComponent();
            
            CultureInfo[] cinfo = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);
            var cinfoSorted = from l in cinfo
                              where l.Name.Contains("-")
                              orderby l.Name ascending
                              select l;
            foreach (CultureInfo cl in cinfoSorted)
            {
                
                RadListDataItem item = new RadListDataItem(cl.DisplayName+" - "+cl.NativeName,cl);
                ListLanguage.Items.Add(item);
            }
        }
        
        

        public System.Globalization.CultureInfo getNew()
        {
            ShowDialog();
            return newLanguage;
        }

        private void BtnOk_Click(object sender, EventArgs e)
        {
            newLanguage = (CultureInfo)ListLanguage.SelectedItem.Value;
            Dispose();
        }

        private void BtnCancel_Click(object sender, EventArgs e)
        {
            newLanguage = null;
            Dispose();
        }
    }
}
